const waitClick = {
  handler(el, binding) {
    if (typeof binding.value === 'function') {
      const waitTime = 1000
      if (!el.dataset.lastTime) {
        el.dataset.lastTime = '-1'
      }
      el.onclick = (e) => {
        const now = new Date().getTime()
        if (now - parseFloat(el.dataset.lastTime) >= waitTime) {
          binding.value(e)
          el.dataset.lastTime = now.toString()
        }
      }
    } else {
      el.onclick = null
    }
  },
  install(app) {
    app.directive('wait-click', {
      mounted: this.handler,
      updated: this.handler,
    })
  },
}

/**
 * 需要使用的自定义指令列表
 */
const commandList = [waitClick]

/**
 * 默认导出的自定义指令
 */
const command = {
  install(app) {
    for (const com of commandList) {
      com.install(app)
    }
  },
}
export default command
